#include<bits/stdc++.h>
using namespace std;
const int N = 35;
int V;
int v[N];
int n;
int dp[N][200001];
int main()
{
    cin >> V >> n;
    for (int i = 0; i < n; i++)cin >> v[i];
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= V; j++)
        {
            dp[i][j] = dp[i - 1][j];
            if (j - v[i - 1] >= 0)
                dp[i][j] = max(dp[i][j], dp[i - 1][j - v[i-1]] + v[i - 1]);
        }
    }
    cout << V - dp[n][V];
    return 0;
}











#include<bits/stdc++.h>
using namespace std;
const int N = 35;
int V;
int v[N];
int n;
int dp[200001];
int main()
{
    cin >> V >> n;
    for (int i = 0; i < n; i++)cin >> v[i];
    for (int i = 1; i <= n; i++)
    {
        for (int j = V; j - v[i - 1] >= 0; j--)
        {
           
                dp[j] = max(dp[j], dp[j - v[i-1]] + v[i - 1]);
        }
    }
    cout << V - dp[V];
    return 0;
}